<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/autoComplete.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/patrol/project_device_alert.css">
    <!-- <link rel="stylesheet" href="{{ layui.setter.base }}layui/css/modules/eleTree/eleTree.css"> -->
    <link rel="stylesheet" href="{{ layui.setter.base }}style/dtree.css">
</script>
<style scope>
    .dataForm {
        background: #ffffff;
    }
    .layui-input-block {
        width: 170px;
    }

    .layui-form-label {
        font-size: 10px;
    }

    .buttons {
        margin-bottom: 20px;
    }

    .InfoButton {
        text-align: center;
    }

    .InfoButton button {
        padding: 0px 21px;
    }

    .InfoButton button:nth-child(1) {
        background: #FF4C4C;
    }

    .InfoButton button:nth-child(2) {
        background: #8A8A8A;
        margin-left: 40px;
    }

    input::-webkit-input-placeholder {
        font-size: 8px;
    }
    .dtree-select-show{
        min-width: 250px;
        height: 250px !important;
    }
    .dtree-select .edgeI{
       display: none;
    }
    .mode {
        border-radius: 6px;
        padding: 10px 15px;
        background: #1E9FFF;
        color: #fff;
        margin-right: 4px;
        margin-bottom: 4px;
        position: relative;
        display: inline-block;
    }

    .mode .deleteMode {
        position: absolute;
        right: 2px;
        top: 2px;
        font-size: 12px;
        cursor: pointer;
    }

    #uploding {
        width: 170px;
        height: 34px;
    }

    .photograph {
        border: 1px solid #eee;
        height: 200px;
        width: 272px;
        margin-top: 25px;
    }

    .layui-form-label {
        float: left;
        display: block;
        padding: 9px 0px;
        width: 88px;
        font-weight: 400;
        line-height: 20px;
        text-align: right !important;
    }

    .Falg {
        position: absolute;
        color: red;
        left: 25px;
        top: 13px;
        font-size: 22px;
    }

    .Falg2 {
        position: absolute;
        color: red;
        left: 0px;
        top: 13px;
        font-size: 22px;
    }

    .Falg3,
    .Falg4,
    .Falg5 {
        position: absolute;
        color: red;
        left: 44px;
        top: 13px;
        font-size: 22px;
    }

    .Falg6 {
        position: absolute;
        color: red;
        left: 23px;
        top: 13px;
        font-size: 22px;
    }
    .leon-style-alert .con2 input{
        margin-right: 0px; 
        padding-left: 0px; 
    }
    .Falges{
        color: red;
        font-size: 23px;
        position: absolute;
        top: 13px;
        left: 24px;
        display: none;
    }   
</style>
<div>
  <div class="dataForm layui-fluid">
    <div class="layui-row">
        <div class="layui-form" lay-filter="dataForms">
            <!-- 第一列 -->
            <div class=" layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>设备编号:</label>
                    <div class="layui-input-block">
                        <input type="text" name="fia01" placeholder="请输入设备编号" autocomplete="off" class="layui-input"
                            lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>公司名称:</label>
                    <div class="layui-input-block">
                        <select name="fiaplant" lay-filter="selectElement" id="account" lay-verify="required">

                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>资产编码:</label>
                    <div class="layui-input-block">
                        <input type="text" name="fia011" placeholder="请输入资产编码" autocomplete="off" class="layui-input"
                            lay-verify="required" id="CodeMa">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>设备名称:</label>
                    <div class="layui-input-block">
                        <input type="text" name="fia02" placeholder="请输入设备名称" autocomplete="off" class="layui-input"
                            lay-verify="required">
                    </div>
                </div>
                <!-- 设备停用启用 -->
                <div class="layui-form-item">
                    <label class="layui-form-label" data-lang="devicename"><i class="Falg2">*</i>设备停用启用:</label>
                    <div class="layui-input-block">
                        <input type="radio" data-lang="yes" name="tcDevIsDisable" value="0" title="启用" checked>
                        <input type="radio" data-lang="no" name="tcDevIsDisable" value="1" title="停用">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>设备类型:</label>
                    <div class="layui-input-block" style="line-height: 38px;">
                        <!-- <input type="text" name="fia03" placeholder="请输入设备类型" autocomplete="off" class="layui-input"
                            id="ThreeOne" lay-verify="required"> -->
                        <div class="dtree" name="fia03" id="ThreeOne"></div>
                        <input type="text" name="fia03" placeholder="请输入设备类型" autocomplete="off" class="layui-input"
                            id="ThreeTwo" style="display: none;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">启动日期:</label>
                    <div class="layui-input-block">
                        <input type="text" name="fia19" placeholder="选择时间" autocomplete="off" class="layui-input"
                            id="startTime" style="cursor:pointer;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">保修日期:</label>
                    <div class="layui-input-block">
                        <input type="text" name="fia20" placeholder="选择时间" autocomplete="off" class="layui-input"
                            id="guaranteeTime" style="cursor:pointer;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">验收日期:</label>
                    <div class="layui-input-block" style="cursor:pointer;">
                        <input type="text" name="tcDevChkdate" placeholder="选择时间" autocomplete="off" class="layui-input"
                            id="checkTime" style="cursor:pointer;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>设备图片:</label>
                    <div class="layui-input-block">
                        <input type="text" name="tcFilePath" placeholder="请输入" autocomplete="off"
                            class="layui-input uploadeImag" value="上传图片" id="uploding" lay-verify="required">
                        <input type="text" name="tcFilePath" class="dataElement" value="" style="display:none;">
                    </div>
                    <!-- 图片预览区域 -->
                    <div class="photograph" style="position:relative;overflow:hidden;padding:4px;">
                        <ul id="path" style='display:flex;flex-wrap:wrap;box-sizing:border-box;overflow:hidden;'></ul>
                    </div>
                </div>
            </div>
            <!-- 第二列 -->
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>设备型号:</label>
                    <div class="layui-input-block">
                        <input type="text" name="fia05" id="fia05" placeholder="" autocomplete="off" class="layui-input"
                            lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>设备系列:</label>
                    <div class="layui-input-block">
                        <input type="text" name="fia04" placeholder="请输入设备系列" autocomplete="off" class="layui-input"
                            lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>设备状态:</label>
                    <div class="layui-input-block">
                        <select name="fiaacti" lay-filter="" lay-verify="required">
                            <option></option>
                            <option value="0">一般</option>
                            <option value="1">良好</option>
                            <option value="2">不稳定</option>
                            <option value="3">折旧中</option>
                            <option value="4">外送</option>
                            <option value="5">折毕</option>
                            <option value="6">出售</option>
                            <option value="7">报废</option>
                            <option value="8">折毕再提</option>
                            <option value="9">改良</option>
                            <option value="A">重估</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>供应商:</label>
                    <div class="layui-input-block">
                        <input type="text" name="fia09" placeholder="请选择供应商" autocomplete="off" class="layui-input"
                            lay-verify="required" id="supplier">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>负责部门:</label>
                    <div class="layui-input-block" style="line-height: 38px;">
                        <!-- <input type="text" name="fia11" placeholder="" autocomplete="off" class="layui-input eleTree ele1"
                            id="treeSelect" lay-verify="required"> -->
                        <div id="treeSelect" class="dtree" data-id="0" style="width:100%;display:block;" data-value="001"></div>
                        <input type="text" name="fia11" placeholder="" autocomplete="off" class="layui-input"
                            style="display: none;" id="treeSelect2" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>保管人:</label>
                    <div class="layui-input-block">
                        <select name="fia10" lay-filter="" id="Custodian" lay-verify="required">

                        </select>
                    </div>
                </div>
                <!-- <div class="layui-form-item">
                    <label class="layui-form-label" data-lang="MachineCapacity">机台能力:</label>
                    <div class="layui-input-block">
                        <div class="modeBox" id="detailBox"></div>
                        <div id="alertChooseOne"><i class="layui-icon layui-icon-add-1"
                                style="font-size: 25px; color: #1E9FFF;"></i>
                        </div>
                    </div>
                </div> -->
                <div class="layui-form-item">
                    <label class="layui-form-label">精度:</label>
                    <div class="layui-input-block">
                        <input type="text" name="tcDevPrecision" placeholder="请输入精度" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
                <!-- <div class="layui-form-item">
                    <label class="layui-form-label">可生产产品类型:</label>
                    <div class="ShanChanType layui-input-block">
                        <div class="modeBox" id="typeBox"></div>
                        <div id="alertChooseTwo"><i class="layui-icon layui-icon-add-1"
                                style="font-size: 25px; color: #1E9FFF;"></i>
                        </div>
                    </div>
                </div> -->
                <div class="layui-form-item">
                    <label class="layui-form-label">正常生产时长:</label>
                    <div class="layui-input-block">
                        <input type="number" name="tcScadaProdtime" placeholder="请输入正常生产时长" autocomplete="off"
                            class="layui-input" id="timeFange" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">待机时长:</label>
                    <div class="layui-input-block">
                        <input type="number" name="tcScadaStdbytime" placeholder="请输入待机时长" autocomplete="off"
                            class="layui-input" id="daijiTime" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">异常时长:</label>
                    <div class="layui-input-block">
                        <input type="number" name="tcScadaExcptime" placeholder="请输入异常时长" autocomplete="off"
                            class="layui-input" id="errorTime" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg">*</i>安全说明:</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入安全说明" class="layui-textarea" name="fia25"
                            lay-verify="required"></textarea>
                    </div>
                </div>
            </div>
            <!-- 第三列 -->
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg2">*</i>设备调机人员:</label>
                    <div class="layui-input-block">
                        <select name="fiauser" lay-filter="" id="diagnoses" lay-verify="required">

                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg3">*</i>厂房:</label>
                    <div class="layui-input-block">
                        <select name="fia14" lay-filter="plantElement" id="plant" lay-verify="required">

                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg4">*</i>楼层:</label>
                    <div class="layui-input-block">
                        <select name="fia15" lay-filter="" id="floorElement" lay-verify="required">

                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg6">*</i>站别/工序:</label>
                    <div class="layui-input-block">
                        <select name="fia16" lay-filter="" id="zhanBie" lay-verify="required">

                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falg5">*</i>线别:</label>
                    <div class="layui-input-block">
                        <select name="fia17" lay-filter="" id="xianBie" lay-verify="required">

                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">购买日期:</label>
                    <div class="layui-input-block">
                        <input type="text" name="fia18" placeholder="选择时间" autocomplete="off" class="layui-input"
                            id="buyTime" style="cursor:pointer;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">维修保养时长:</label>
                    <div class="layui-input-block">
                        <input type="number" name="tcScadaMainttime" placeholder="请输入维修时长" autocomplete="off"
                            class="layui-input" id="baoYangTime" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">产量:</label>
                    <div class="layui-input-block">
                        <input type="number" name="tcScadaProduction" placeholder="请输入产量" autocomplete="off"
                            class="layui-input" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否联机:</label>
                    <div class="layui-input-block">
                        <input type="radio" name="tcScadaIsonine"  lay-filter="tcScadaIsonineY" value="Y" title="是">
                        <input type="radio" name="tcScadaIsonine"  lay-filter="tcScadaIsonineY" value="N" title="否" checked>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falges">*</i>驱动类型:</label>
                    <div class="layui-input-block">
                        <input type="text" name="tcScadaDrvtype" placeholder="请输入驱动类型" autocomplete="off"
                            class="layui-input" id="driveType" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falges">*</i>驱动名称:</label>
                    <div class="layui-input-block">
                        <input type="text" name="tcScadaDrvname" placeholder="请输入驱动名称" autocomplete="off"
                            class="layui-input" id="driveName" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="Falges">*</i>设备IP:</label>
                    <div class="layui-input-block">
                        <input type="text" name="tcScadaIpaddress" placeholder="请输入设备IP" autocomplete="off"
                            class="layui-input" id="facilityIp" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注:</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入备注" class="layui-textarea" name="fia22"></textarea>
                    </div>
                </div>
            </div>
            <!-- 确定和取消 -->
            <div class="layui-col-md12">
                <div class="InfoButton">
                    <button class="layui-btn layui-btn-xs layui-btn-radius" lay-submit
                        lay-filter="formSubmlitButton2">确定</button>
                    <button class="layui-btn layui-btn-xs layui-btn-radius" id="cancel">取消</button>
                </div>
            </div>
            
        </div>
    </div>
</div>
</div>

<!-- 机台能力 -->
<script type="text/html" id="addDeviceTpl">
<div class="leon-style-alert">
  <div class="layui-alert-box">
    <div class="layui-alert-title">
      <span class="layui-title-inner">机台能力</span>
      <span class="layui-title-screen">
      </span>
    </div>
    <div class="layui-content">
      <div class="con1 toggle-btn">
        <span class="screen">
          <i class="query-icon  layui-icon"></i>
          <span class="query-inner">查询条件</span>
        </span>
        <i class="icon layui-icon layui-icon-down"></i>
      </div>
      <div class="con2 toggle-content">
        <form action="" class="layui-form">
          <label for="">机台能力编号:</label>
          <input type="text" name="id" />
          <label for="">机台能力名称:</label>
          <input type="text" name="name" />
          <label for="">机台能力描述:</label>
          <input type="text" name="dsc" />
          <button type="button" lay-submit lay-filter="queryTableDevice"
            class="query layui-btn layui-btn-radius layui-btn-primary">
            <span class="search-icon"></span>
            <span class="btn-inner">查询</span>
          </button>
        </form>
      </div>
      <table class="layui-table" id="MachineCapacityTable"></table>
    </div>
    <div class="footer layui-btn-containner">
      <button class="btn1 layui-btn layui-btn-radius layui-btn-primary">确定</button>
      <button class="btn2 layui-btn layui-btn-radius layui-btn-primary">取消</button>
    </div>
  </div>
</div>
</script>
<!-- 可生产产品类型 -->
<script type="text/html" id="addDeviceTpl2">
<div class="leon-style-alert">
  <div class="layui-alert-box">
    <div class="layui-alert-title">
      <span class="layui-title-inner">可生产产品类型</span>
      <span class="layui-title-screen">
      </span>
    </div>
    <div class="layui-content">
      <div class="con1 toggle-btn">
        <span class="screen">
          <i class="query-icon  layui-icon"></i>
          <span class="query-inner">查询条件</span>
        </span>
        <i class="icon layui-icon layui-icon-down"></i>
      </div>
      <div class="con2 toggle-content">
        <form action="" class="layui-form">
          <label for="">产品类型编号:</label>
          <input type="text" name="id" />
          <label for="">产品类型名称:</label>
          <input type="text" name="name" />
          <label for="">产品类型描述:</label>
          <input type="text" name="dsc" />
          <button type="button" lay-submit lay-filter="queryTableDevice"
            class="query layui-btn layui-btn-radius layui-btn-primary">
            <span class="search-icon"></span>
            <span class="btn-inner">查询</span>
          </button>
        </form>
      </div>
      <table class="layui-table" id="ProdicobleType"></table>
    </div>
    <div class="footer layui-btn-containner">
      <button class="btn1 layui-btn layui-btn-radius layui-btn-primary">确定</button>
      <button class="btn2 layui-btn layui-btn-radius layui-btn-primary">取消</button>
    </div>
  </div>
</div>
</script>
<!-- 供应商 -->
<script type="text/html" id="addDeviceTpl3">
    <style scoped>
        .leon-style-alert .layui-table-page,.layui-table-page .layui-laypage input{
                background-color:transparent;   
           }
           .leon-style-alert .layui-table-view {
             border-width: 1px;
             border-style: solid;
             border-color: #e6e6e6;
         }
     </style>
<div class="leon-style-alert">
  <div class="layui-alert-box">
    <div class="layui-alert-title">
      <span class="layui-title-inner">供应商</span>
    </div>
    <div class="layui-content">
      <div class="con1 toggle-btn">
        <span class="screen">
          <i class="query-icon  layui-icon"></i>
          <span class="query-inner">查询条件</span>
        </span>
        <i class="icon layui-icon layui-icon-down"></i>
      </div>
      <div class="con2 toggle-content">
        <form action="" class="layui-form">
          <label for="">供应商:</label>
          <input type="text" name="pmc081" />
          <button type="button" lay-submit lay-filter="queryTableDevice"
            class="query layui-btn layui-btn-radius layui-btn-primary">
            <span class="search-icon"></span>
            <span class="btn-inner">查询</span>
          </button>
        </form>
      </div>
      <table class="layui-table" id="table-device-alert" style="margin-top:20px;"></table>
    </div>
    <div class="footer layui-btn-containner" style="margin-top:20px;">
      <button class="btn1 layui-btn layui-btn-radius layui-btn-primary">确定</button>
      <button class="btn2 layui-btn layui-btn-radius layui-btn-primary">取消</button>
    </div>
  </div>
</div>
</script>

<script type="text/javascript">
    layui.use(["form", "api", "view", "upload", "laydate", "laytpl", "view", "admin", "layer", "element", "table", "treeSelect", 'utill','eleTree','dtree'], function () {
        var api = layui.api;
        var form = layui.form;
        var view = layui.view;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var view = layui.view;
        var admin = layui.admin;
        var layer = layui.layer;
        var $ = layui.$;
        var table = layui.table;
        var setter = layui.setter;
        var element = layui.element;
        var utill = layui.utill;
        var treeSelect = layui.treeSelect;
        var eleTree = layui.eleTree;
        var dtree = layui.dtree;
        var router = layui.router();
        form.render();
        // console.log(dtree);
        // 时间组件
        laydate.render({
            elem: "#startTime",
            type: 'datetime',
            trigger: 'click',
            btns: ['confirm', 'clear']
        });
        laydate.render({
            elem: "#guaranteeTime",
            type: 'datetime',
            trigger: 'click',
            btns: ['confirm', 'clear']
        });
        laydate.render({
            elem: "#checkTime",
            type: 'datetime',
            trigger: 'click',
            btns: ['confirm', 'clear']
        });
        laydate.render({
            elem: "#buyTime",
            type: 'datetime',
            trigger: 'click',
            btns: ['confirm', 'clear']
        });
        form.on('radio(tcScadaIsonineY)', function(data){
         var data = data.value;
         if(data == 'Y'){
           $("#driveType").attr("lay-verify", "required");
           $("#driveName").attr("lay-verify", "required");
           $("#facilityIp").attr("lay-verify", "required");
           $("#driveType").removeAttr("disabled");
           $("#driveName").removeAttr("disabled");
           $("#facilityIp").removeAttr("disabled");
           $(".Falges").css('display','block');
         }else{
           $(".Falges").css('display','none');
           $("#driveType").removeAttr("lay-verify","required");
           $("#driveName").removeAttr("lay-verify","required");
           $("#facilityIp").removeAttr("lay-verify","required");
           $("#driveType").attr("disabled", "disabled");
           $("#driveName").attr("disabled", "disabled");
           $("#facilityIp").attr("disabled", "disabled");
           $("#driveType").val("");
           $("#driveName").val("");
           $("#facilityIp").val("");
         }
   	 }); 
        // 负责部门升级本
        function mydtree(data){
                 dtree.renderSelect({
                    elem: "#treeSelect",
                    width: "100%", // 指定树的宽度
                    url: api.host + api.selectCoaltDept,
                    headers:{ 
                    'token': layui.sessionData(setter.tableName).token 
                    },
                    dataType: "json",
                    async: false,
                    request: {
                    tcReqCoalt: data,
                    token: layui.sessionData(setter.tableName).token 
                    },
                    errDataShow: true,
                    method: 'get',
                    initLevel: false,
                    icon:false,
                    accordion: true,
                    response: {
                    statusName: "code", //返回标识（必填）
                    statusCode: 0, //返回码（必填）
                    message: "message", 
                    rootName: "data", //根节点名称（必填）
                    title: "gem02",//节点名称（必填）
                    treeId: "gem01",//节点ID（必填）
                    childName: "deptVOS",//子节点名称（默认数据格式必填)
                    }
             });
             dtree.on('node("treeSelect")', function(obj){
                var param = dtree.selectVal("treeSelect");
                $('#treeSelect2').val(param.treeSelect_select_nodeId)
             });
             console.log(2)

        }
        function mydtreeTwo(data){
                 dtree.renderSelect({
                    elem: "#ThreeOne",
                    width: "100%", // 指定树的宽度
                    url: api.host + api.selectFic01_llp,
                    headers:{ 
                    'token': layui.sessionData(setter.tableName).token 
                    },
                    dataType: "json",
                    async: false,
                    request: {
                    tcReqCoalt: data,
                    token: layui.sessionData(setter.tableName).token 
                    },
                    errDataShow: true,
                    method: 'get',
                    initLevel: false,
                    icon:false,
                    accordion: true,
                    response: {
                    statusName: "code", //返回标识（必填）
                    statusCode: 0, //返回码（必填）
                    message: "message", 
                    rootName: "data", //根节点名称（必填）
                    title: "fic02",//节点名称（必填）
                    treeId: "fic01",//节点ID（必填）
                    childName: "child",//子节点名称（默认数据格式必填)
                    }
             });
             dtree.on('node("treeSelect")', function(obj){
                var param = dtree.selectVal("treeSelect");
                $('#treeSelect2').val(param.treeSelect_select_nodeId)
             });
        }
         $("body").on("click", function(event){
            $("div[dtree-id][dtree-select]").removeClass("layui-form-selected");
            $("div[dtree-id][dtree-card]").removeClass("dtree-select-show layui-anim layui-anim-upbit");
         });
        // 账套
        admin.req({
            type: "post",
            url: api.host + api.AzpSelectAllAzp_llp,
            success: function (data) {
                var data_llp = data.data;
                var code = data.code;
                if (code == 0 || data_llp != "") {
                    var datas_llp = "<option></option>";
                    data_llp.forEach((item) => {
                        datas_llp += `<option value=${item.azp01}>${item.azp02}</option>`;
                    });
                    $("#account").html(datas_llp);
                    mydtree('');
                    mydtreeTwo('');
                    form.render("select", "dataForms");
                }
            }
        });
        //获得
        $("#plant").attr('disabled', 'disabled');          //给厂房添加禁用效果
        $("#Custodian").attr('disabled', 'disabled');      //保管人添加禁用效果
        $("#diagnoses").attr('disabled', 'disabled');      //设备调机人员禁用效果
        $("#floorElement").attr('disabled', 'disabled');   //楼层禁用效果
        $("#treeSelect").attr('disabled', 'disabled');      //负责部门
        form.on("select(selectElement)", function (data) {
            var account = $("#account").val();
            $("#floorElement").empty();
            dtree.reload("treeSelect",{  
              request: {
                tcReqCoalt: account,
                token: layui.sessionData(setter.tableName).token 
              }
            });
            dtree.reload("ThreeOne",{  
              request: {
                tcReqCoalt: account,
                token: layui.sessionData(setter.tableName).token 
              }
            });
            if (account != null && account != "") {
                $("#plant").removeAttr('disabled','disabled');
                $("#Custodian").removeAttr('disabled','disabled');
                $("#treeSelect").removeAttr('disabled', 'disabled');
            }else{
                $("#plant").attr('disabled','disabled');
                $("#Custodian").attr('disabled','disabled');
                $("#treeSelect").attr('disabled', 'disabled');
            }
            form.render();
            var llp = '';
            var Object = {
                "codId": account,
                "param": llp
            }
            admin.req({    //厂房
                url: api.host + api.selectFactoryName_llp,
                type: "post",
                dataType: "json",
                contentType: "application/json",
                data: JSON.stringify(Object),
                success: function (res) {
                    var responsePa = res.data;
                    var code = res.code;
                    if (responsePa != null || responsePa != "") {
                        var cf_llp = '<option></option>';
                        responsePa.forEach((item) => {
                            cf_llp += `<option value=${item.TC_FTY_ID}>${item.TC_FTY_NAME}</option>`
                        })
                        $('#plant').html(cf_llp);
                        form.render("select");
                    }
                }
            });
            
            function lc(data){
              admin.req({
                    url: api.host + api.selectDevFactoryName_llp,
                    type: "post",
                    dataType: "json",
                    contentType: "application/json",
                    data: JSON.stringify(data),
                    success: function (res) {
                        var footers_llp = res.data;
                        if (footers_llp != null || footers_llp != "") {
                            var _footer = '';
                            footers_llp.forEach((item) => {
                                _footer += `<option value=${item.TC_FLR_ID}>${item.TC_FLR_NAME}</option>`
                            })
                            $('#floorElement').html(_footer);
                            form.render("select");
                        }
                    }
                });
            }
            // 楼层
            form.on("select(plantElement)", function (data) {
                var plant = $("#plant").val();
                var Objects = {
                    "id": plant
                }
                if (plant != "" && plant != null) {
                    $("#floorElement").removeAttr('disabled','disabled');
                    lc(Objects);
                }else{
                    $("#floorElement").attr('disabled','disabled');
                }
                form.render();  
            })
            // 设备调机人员
            
            var param = "";
            var Ponser = {
                id: account,
                param: param
            }
            if (account != "") {
                $("#diagnoses").removeAttr('disabled');
            } else {
                $("#diagnoses").attr('disabled', 'disabled');
            }
            form.render();

            admin.req({
                type: "post",
                dataType: "json",
                contentType: "application/json",
                url: api.host + api.selectAzpPeople_llp,
                data: JSON.stringify(Ponser),
                success: function (response) {
                    var code = response.code;
                    var response = response.data;
                    if (code == 0 || response != null || response.size != 0) {
                        var _res = "<option></option>";
                        response.forEach(item => {
                            _res += `<option value=${item.TC_HR_GEN01}>${item.GEN02}</option>`;
                        });
                        $("#diagnoses").html(_res);
                        form.render("select");
                    }
                }
            });
            // 保管人
            var param = "";
            var Ponser = {
                id: account,
                param: param
            }
            admin.req({
                type: "post",
                dataType: "json",
                contentType: "application/json",
                url: api.host + api.selectAzpPeople_llp,
                data: JSON.stringify(Ponser),
                success: function (response) {
                    var code = response.code;
                    var response = response.data;
                    if (code == 0 || response != null || response != "") {
                        var _res = "<option></option>";
                        response.forEach(item => {
                            _res += `<option value=${item.TC_HR_GEN01}>${item.GEN02}</option>`;
                        });
                        $("#Custodian").html(_res);
                        form.render("select");
                    }
                }
            });
            // 设备类型
            // admin.req({
            //     url: api.host + api.selectFic01_llp,
            //     success: function (response_llp) {
            //         function transferKey(odata) {
            //             if (odata != "" || odata != null) {
            //                 odata.forEach(obj => {
            //                     obj.title = obj.fic02
            //                     obj.children = obj.child
            //                     delete obj["fic02"]
            //                     delete obj["child"]
            //                     if (obj.children instanceof Array) {
            //                         transferKey(obj.children)
            //                     }
            //                 })
            //             }
            //             return odata
            //         }
            //         odataArr = transferKey(response_llp.data)
            //         treeSelect.render({
            //             elem: "#ThreeOne",
            //             node: odataArr,
            //             done: (data) => {
            //                 $("#ThreeOne").val(data.data.title);
            //                 $("#ThreeTwo").val(data.data.fic01);
            //             }
            //         })
            //     }
            // });

        })

        // 站别
        admin.req({
            type: "post",
            url: api.host + api.selectFiaProcId,
            success: function (data) {
                var data = data.data;
                var code = data.code;
                if (data != null || data.size > 0) {
                    var _datas = "<option></option>";
                    data.forEach(item => {
                        _datas += `<option value=${item.tcProcId}>${item.tcProcName}</option>`;
                    });
                    $("#zhanBie").html(_datas);
                    form.render("select");
                }
            }
        });
        // 线别
        admin.req({
            type: "post",
            url: api.host + api.selectFiaLineId,
            success: function (data) {
                var list = data.data;
                var code = data.code;
                if (code == 0 || list != "" || list != null) {
                    var _list = "<option></option>";
                    list.forEach(item => {
                        _list += `<option value=${item.tcLineId}>${item.tcLineName}</option>`;
                    });
                    $("#xianBie").html(_list);
                    form.render("select");
                }
            }
        });
        var allData = {
            details: [],
            type: []
        }
        // 机台能力弹出层
        $("#alertChooseOne").click(function () {
            layer.open({
                type: 1,
                title: false,
                area: ["662px", "536px"],
                fixed: true,
                shadeClose: true,
                closeBtn: 0,
                content: $("#addDeviceTpl").html(),
                success: alertEvent.addDevice
           });   
        });
        // 可生产产品类型
        $("#alertChooseTwo").click(function () {
            layer.open({
                type: 1,
                title: false,
                area: ["662px", "536px"],
                fixed: true,
                shadeClose: true,
                closeBtn: 0,
                content: $("#addDeviceTpl2").html(),
                success: alertEvent.addDevice2
           });
        });
        // 供应商
        $("#supplier").click(function(){
            layer.open({
                type: 1,
                title: false,
                area: ["665px", "536px"],
                fixed: true,
                shadeClose: true,
                closeBtn: 0,
                content: $("#addDeviceTpl3").html(),
                success: alertEvent.addRoleAlert3
            });
        })
        // 进行规制校验
        //(1:驱动类型的校验)
        $("#driveType").blur(function () {
            if ($("#driveType").val().length > 20) {
                layer.msg('输入过长,请输入20以内');
                $("#driveType").val("");
            }
        })
        //驱动名称
        $("#driveName").blur(function () {
            if ($("#driveName").val().length > 20) {
                layer.msg('输入过长,请输入20以内');
                $("#driveName").val("");
            }
        })
        //设备IP
        $("#facilityIp").blur(function () {
            if ($("#facilityIp").val().length > 15) {
                layer.msg('输入过长,请输入15以内');
                $("#facilityIp").val("");
            }
        })
        $("#CodeMa").blur(function(){
          var text = $("#CodeMa").val();
          var textlen = $("#CodeMa").val().length
          if(textlen>10){
                var lenText=text.substring(0,10);
                $("#CodeMa").val(lenText);
            }
        });
        // 正常生产时长 daijiTime
        $("#timeFange").keyup(function () {
            $(this).val(ChangeNumValue($(this).val()));
        })

        // 待机时长
        $("#daijiTime").keyup(function () {
            $(this).val(ChangeNumValue($(this).val()));
        })

        // 异常时长 errorTime
        $("#errorTime").keyup(function () {
            $(this).val(ChangeNumValue($(this).val()));
        })
        //保养时长
        $("#baoYangTime").keyup(function () {
            $(this).val(ChangeNumValue($(this).val()));
        })
        // 数据只保留1位小数
        function ChangeNumValue(tmpVal) {
            if (tmpVal) {
                var tmpVal = tmpVal.replace(/[^\d\.]/g, '');
                var reg = /^(0|([1-9]\d*))(\.\d{1,1})?$/; //正则验证保留 最多允许后输入两位小数
                if (!reg.test(tmpVal)) {
                    tmpVal = tmpVal + "";
                    tmpVal = tmpVal.substring(0, tmpVal.indexOf(".") + 2);
                    var n = (tmpVal.split('.')).length - 1;
                    if (n > 1) {
                        tmpVal = tmpVal.substring(0, tmpVal.indexOf("."));
                    }
                }
                return tmpVal;
            } else {
                return "";
            }
        }
        //文件上传功能
        var arr = [];
        var index = 0;
        //执行实例
        var uploadInst = upload.render({
            elem: "#uploding",
            url: api.host + api.upload_llp,
            multiple: true,
            size: 100000000,
            method: "post",
            accept: "images",
            headers: { 'token': layui.sessionData(setter.tableName).token },
            done: function (res) {
                arr.push({
                    img: res.data[0],
                    index: ++index
                });
                var i = 1;
                $("#path").append(
                    "<li Style='color: red;position:relative'><img class='closeBtn' style='position:absolute;top:-4px;right:0' src='./../../../../dist/img/close.png'><img class='imagesUpload' src= '" + api.imghost + "/" +
                    res.data[0] +
                    "' style='width: 40px; height: 40px;margin:2px'/><input class='path' value=" +
                    res.data[0] +
                    " style='display:none' /></li>"
                );
                i++;
                // 点击关闭图片和关闭按钮取消
                $(".closeBtn").click(function () {
                    var _llpImag = $(this).next();
                    let imghost = api.imghost + "\/";
                    var imgpath = _llpImag.attr('src');
                    // var obj = {}
                    for (let i = 0; i < arr.length; i++) {
                        if (arr[i].img == imgpath) {
                            arr.splice(i, 1);
                        }
                    }
                    _llpImag.remove();
                    $(this).remove();
                })
            }
        });
        // 设备系列
        utill.fuzzmatch('#fia05', {
            isShowValue: false,
            reqObj: {
                url: api.host + api.selectFiaFii02,
                type: 'POST'
            },
            dataTrans: function (res) {
                return res.data.map((item) => {
                    return {
                        label: item.fii02,
                        value: item.fii02,
                        data: item
                    }
                })
            }
        });
        // form数据表单提价
        form.on('submit(formSubmlitButton2)', function (data) {
            var field = data.field;
            var fia01 = field.fia01;                          //设备编号
            var fiaplant = field.fiaplant;                    //账套
            var fia011 = field.fia011;                        //资产编号
            var fia02 = field.fia02;                          //设备名称
            var tcDevIsDisable = field.tcDevIsDisable;        //设备停用启用
            var fia03 = field.fia03;                          //设备类型
            var fia19 = field.fia19;                          //启动日期
            var fia20 = field.fia20;                          //保修日期
            var tcDevChkdate = field.tcDevChkdate;            //验收日期
            var fia05 = field.fia05;                          //设备型号
            var fia04 = field.fia04;                          //设备系列
            var fiaacti = field.fiaacti;                      //设备状态
            var fia09 = field.fia09;                          //供应商
            var fia11 = field.fia11;                          //负责部门
            var fia10 = field.fia10;                          //保管人
            // var tcCapCapId = field.tcCapCapId;                //机台能力
            var tcDevPrecision = field.tcDevPrecision;        //精度
            // var tcProdProdId = field.tcProdProdId;            //可生产产品类型
            var tcScadaProdtime = field.tcScadaProdtime;      //正常生产时间
            var tcScadaStdbytime = field.tcScadaStdbytime;    //待机时长
            var tcScadaExcptime = field.tcScadaExcptime;      //异常时长
            var fia25 = field.fia25;                          //安全说明
            var fiauser = field.fiauser;                      //设备调机人员
            var fia14 = field.fia14;                          //厂房
            var fia15 = field.fia15;                          //楼层
            var fia16 = field.fia16;                          //站别和工序
            var fia17 = field.fia17;                          //线别
            var fia18 = field.fia18;                          //购买日期
            var tcScadaMainttime = field.tcScadaMainttime;    //维修时长 
            var tcScadaProduction = field.tcScadaProduction;  //产量     
            var tcScadaIsonine = field.tcScadaIsonine;        //是否联机   
            var tcScadaDrvtype = field.tcScadaDrvtype;        //驱动类型    
            var tcScadaDrvname = field.tcScadaDrvname;        //驱动名称
            var tcScadaIpaddress = field.tcScadaIpaddress;    //设备IP
            var fia22 = field.fia22;                          //备注
            var arrs = [];
            var arrs2 = [];

            // 图片
            var paths = [];
            // 机台能力
            allData.details.map(function (item) {
                arrs.push(item.TC_CAP_ID);
            })

            // 可生产产品类型
            allData.type.map(function (item) {
                arrs2.push(item.TC_PROD_ID);
            })

            arr.forEach(function (item) {
                paths.push(item.img);
            })
            var obj = {
                tcFilePath: paths,
                fia01: fia01,
                fiaplant: fiaplant,
                tcDevIsDisable:tcDevIsDisable,
                fia011: fia011,
                fia02: fia02,
                fia03: fia03,
                fia19: fia19,
                fia20: fia20,
                tcDevChkdate: tcDevChkdate,
                fia05: fia05,
                fia04: fia04,
                fiaacti: fiaacti,
                fia09: fia09,
                fia11: fia11,
                fia10: fia10,
                // tcCapCapId: arrs,
                tcDevPrecision: tcDevPrecision,
                // tcProdProdId: arrs2,
                tcScadaProdtime: tcScadaProdtime,
                tcScadaStdbytime: tcScadaStdbytime,
                tcScadaExcptime: tcScadaExcptime,
                fia25: fia25,
                fiauser: fiauser,
                fia14: fia14,
                fia15: fia15,
                fia16: fia16,
                fia17: fia17,
                fia18: fia18,
                tcScadaMainttime: tcScadaMainttime,
                tcScadaProduction: tcScadaProduction,
                tcScadaIsonine: tcScadaIsonine,
                tcScadaDrvtype: tcScadaDrvtype,
                tcScadaDrvname: tcScadaDrvname,
                tcScadaIpaddress: tcScadaIpaddress,
                fia22: fia22
            }
            // 设备录入
            admin.req({
                type: "post",
                dataType: "json",
                contentType: "application/json",
                url: api.host + api.insertFiaFile,
                data: JSON.stringify(obj),
                success: function (data) {
                    var code = data.code;
                    if (code == 0) {
                        layer.msg(data.message);
                        location.hash = '/home/cash' 
                    } else {
                        layer.msg(data.message);
                    }
                }
            });
        });
        $('#cancel').click(function () {
            $('#cancel').attr('lay-href', 'home/cash');
        });
        // 事件(机台能力弹出层)
        var alertEvent = {
            // addDevice: function (layero, index) {
            //    table.render(
            //     $.extend({}, utill.tableOpts(), {
            //     elem: "#MachineCapacityTable",
            //     id: "#MachineCapacityTable",
            //     height: 300,
            //     toolbar: "",
            //     url: api.host + api.selectCapacitys_llp,
            //     type: 'post',
            //     cols: [
            //         [
            //         { fixed: "left", type: "checkbox" },
            //         { field: "TC_CAP_CODE", title: "机台能力编号" },
            //         { field: "TC_CAP_NAME", title: "机台能力名称" },
            //         { field: "TC_CAP_DSC", title: "机台能力描述" }
            //         ]
            //     ]
            //     })
            //    );
            //  $('.leon-style-alert .con1').click(function(){
            //    $('.con2').toggle();
            //  })
            // //  条件查询
            // form.on("submit(queryTableDevice)", function (data) {
            //     var allData = data.field;
            //     table.reload("#MachineCapacityTable", {
            //     where: allData
            //     });
            //     return false;
            //  });
            // //确定按钮
            // $(".btn1").click(function(){
            //     var checkStatus = table.checkStatus('#MachineCapacityTable');
            //     if (checkStatus.data.length == 0) {
            //         parent.layer.msg('至少选择一条');
            //         return;
            //     }
            //     var CheckBox = [];
            //     var CheckBoxs = [];
            //     for (var i = 0; i < checkStatus.data.length; i++) {
            //         CheckBox.push(checkStatus.data[i].TC_CAP_NAME);
            //         CheckBoxs.push(checkStatus.data[i].TC_CAP_ID);
            //     }
            //     if (allData.details.length > 0) {
            //         for (var i = 0; i < allData.details.length; i++) {
            //             for (var j = 0; j < checkStatus.data.length; j++) {
            //                 if (checkStatus.data[j].TC_CAP_ID == allData.details[i].TC_CAP_ID) {
            //                     checkStatus.data.splice(j, 1)
            //                     j = j - 1;
            //                 }
            //             }
            //         }
            //     }
            //     checkStatus.data.map(function (dataItem, dataIndex) {
            //         var modeTPL = `<span class="mode">${dataItem.TC_CAP_NAME}<i class="layui-icon layui-icon-close deleteMode"></i></span>`;
            //         $('#detailBox').append(modeTPL)
            //         allData.details.push(dataItem)
            //     })
            //     $('#detailBox').on('click', '.deleteMode', function (e) {
            //         var $target = $(e.target),
            //             cur = $target.parents('.mode'),
            //             idx = $target.parents('.mode').index();
            //         allData.details.splice(idx, 1);
            //         cur.remove();
            //     })
            //     // 成功后关闭
            //     layer.close(index);
            // })
            // // 取消按钮
            // $(".btn2").click(function(){
            //    layer.close(index);
            // })
            // },
            // addDevice2:function(layero, index){
            //   table.render(
            //     $.extend({}, utill.tableOpts(), {
            //     elem: "#ProdicobleType",
            //     id: "#ProdicobleType",
            //     height: 300,
            //     toolbar: "",
            //     url: api.host + api.selectProducts_llp,
            //     type: 'post',
            //     cols: [
            //         [
            //         { fixed: "left", type: "checkbox" },
            //         { field: "TC_PROD_CODE", title: "产品类型编号" },
            //         { field: "TC_PROD_NAME", title: "产品类型名称" },
            //         { field: "TC_PROD_DSC", title: "产品类型描述" }
            //         ]
            //     ]
            //     })
            //    );
            //    //查询显示和隐藏
            //    $('.leon-style-alert .con1').click(function(){
            //       $('.con2').toggle();
            //    })
            //    //高查
            //    form.on("submit(queryTableDevice)", function (data) {
            //         var allData = data.field;
            //         table.reload("#ProdicobleType", {
            //         where: allData
            //         });
            //         return false;
            //    })
            //    //点击确定按钮
            //    $(".btn1").click(function(){
            //     var checkStatus = table.checkStatus('#ProdicobleType');
            //         if (checkStatus.data.length == 0) {
            //             parent.layer.msg('至少选择一条');
            //             return;
            //         }
            //         var CheckBox2 = [];
            //         var CheckBox2s = [];
            //         for (var i = 0; i < checkStatus.data.length; i++) {
            //             CheckBox2.push(checkStatus.data[i].TC_PROD_ID);
            //             CheckBox2s.push(checkStatus.data[i].TC_PROD_NAME);
            //         }
            //         if (allData.type.length > 0) {
            //             for (var i = 0; i < allData.type.length; i++) {
            //                 for (var j = 0; j < checkStatus.data.length; j++) {
            //                     if (checkStatus.data[j].TC_PROD_ID == allData.type[i].TC_PROD_ID) {
            //                         checkStatus.data.splice(j, 1)
            //                         j = j - 1;
            //                     }
            //                 }
            //             }
            //         }
            //         checkStatus.data.map(function (dataItem, dataIndex) {
            //             var modeTPL = `<span class="mode">${dataItem.TC_PROD_NAME}<i class="layui-icon layui-icon-close deleteMode"></i></span>`;
            //             $('#typeBox').append(modeTPL)
            //             allData.type.push(dataItem)
            //         })
            //         $('#typeBox').on('click', '.deleteMode', function (e) {
            //             var $target = $(e.target),
            //                 cur = $target.parents('.mode'),
            //                 idx = $target.parents('.mode').index();
            //             allData.type.splice(idx, 1);
            //             cur.remove();
            //         })
            //         // 成功后关闭
            //         layer.close(index);
            //    })
            //    $(".btn2").click(function(){
            //       layer.close(index);
            //    })
            // },
            addRoleAlert3:function(layero, index){
              table.render(
                $.extend({}, utill.tableOpts(), {
                elem: "#table-device-alert",
                id: "#table-device-alert",
                height: 300,
                toolbar: "",
                url: api.host + api.selectFiaPmc01,
                type: 'post',
                cols: [
                        [
                        { fixed: "left", type: "radio" },
                        { field: "pmc081", title: "供应商" },
                        ]
                      ]
                })
           );
           $('.leon-style-alert .con1').click(function(){
              $('.con2').toggle();
           })
           form.on("submit(queryTableDevice)", function (data) {
                    var allData = data.field;
                    table.reload("#table-device-alert", {
                    where: allData
                    });
                    return false;
            });

            // 确定按钮
            $(".btn1").click(function(){
                tableArray = table.checkStatus("#table-device-alert").data;
                var pmc01 = tableArray[0].pmc01;
                var pmc081 = tableArray[0].pmc081;
                $("#supplier").val(pmc081);
                layer.close(index);

            })
            // 取消
            $(".btn2").click(function(){
                 layer.closeAll();
            })
            }
        }
    })
</script>